#include <iostream>
#include <sstream>
#include "Xern/Json.hpp"
#include "Xern/Vector.hpp"

using namespace Xern;

int main(int argc, const char *argv[])
{
	// Test xern json.
	JsonObject subobject;
	subobject["bool"] = false;
	subobject["null"] = JsonNull();
	subobject["string"] = "test string\n\r";

	JsonArray array;
	array.push_back(1);
	array.push_back(1.5);
	array.push_back("test");

	JsonObject object;
	object["int"] = 123;
	object["double"] = 1.0;
	object["object"] = subobject;
	object["array"] = array;

	// Print into a string stream.
	std::stringstream ss;
	ss << object << std::ends;

	// Print the memory version.
	std::cout << "Original Json:" << std::endl;
	std::cout << ss.str() << std::endl;

	// Read from the string stream.
	JsonValue value;
	ss >> value;

	std::cout << "Readed Json:" << std::endl;
	std::cout << value << std::endl;

	// Try with vectors.
	Vector3 v(1.0, 3.1496, 2.0);
	std::stringstream vss;
	vss << v << std::ends;
	vss.unsetf(std::ios_base::skipws);
	std::cout << "v:" << vss.str() << std::endl;

	vss >> v;
	std::cout << "new v:" << v << std::endl;

	return 0;
}
